//
//  AboutCarViewController.m
//  JiongTu
//
//  Created by Dupengfei on 16/5/4.
//  Copyright © 2016年 YSKJ. All rights reserved.
//

#import "AboutCarViewController.h"
#import "CarInfoViewController.h"
@interface AboutCarViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@end

@implementation AboutCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDateSource];
    [self initializeInterface];
}

-(void)initializeInterface
{
    [self.view addSubview:self.tableView];
}

-(void)initializeDateSource
{
 self.title =@"车辆型号";
}

#pragma mark delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _aboutCar.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identify = @"Cell";
    
      UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identify];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
    }

    cell.textLabel.text = _aboutCar[indexPath.row];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 
    
    NSString * string = [[NSUserDefaults standardUserDefaults]objectForKey:@"carName"];
    
    [[NSUserDefaults standardUserDefaults] setObject:[string stringByAppendingString:_aboutCar[indexPath.row]] forKey:@"carName"];
    
    [self.navigationController popToViewController:self.navigationController.viewControllers[2] animated:YES];
}

#pragma mark-getter
-(UITableView *)tableView
{
    if (_tableView==nil) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.delegate =self;
        _tableView.dataSource =self;
    }
    return _tableView;
}

#pragma mark-setter
-(void)setAboutCar:(NSArray *)aboutCar
{
    _aboutCar =aboutCar;
}


@end
